<template>
  <div class="page-container">
    <!-- 顶部卡片 -->
    <a-card class="header-card">
      <div class="header-content">
        <h2 class="page-title">修改手机号</h2>
        <div class="header-right">
          <a-button type="primary" @click="$router.back()">返回</a-button>
        </div>
      </div>
    </a-card>

    <!-- 修改手机表单 -->
    <div class="form-container">
      <a-card>
        <a-form :model="form" layout="horizontal" :label-col="{ span: 4 }" :wrapper-col="{ span: 16 }">
          <a-form-item label="当前手机号">
            <a-input value="138****8888" disabled />
          </a-form-item>
          <a-form-item label="新手机号" required>
            <a-input v-model:value="form.phone" placeholder="请输入新手机号" />
          </a-form-item>
          <a-form-item label="验证码" required>
            <div class="verify-code">
              <a-input v-model:value="form.code" placeholder="请输入验证码" />
              <a-button 
                :disabled="cooldown > 0" 
                @click="handleSendCode"
                class="send-code-btn"
              >
                {{ cooldown > 0 ? `${cooldown}s` : '获取验证码' }}
              </a-button>
            </div>
          </a-form-item>
          <a-form-item :wrapper-col="{ offset: 4, span: 16 }">
            <a-button type="primary" @click="handleSubmit">确认修改</a-button>
          </a-form-item>
        </a-form>
      </a-card>
    </div>
  </div>
</template>

<script>
import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { message } from 'ant-design-vue'

export default {
  name: 'UpdatePhone',
  setup() {
    const router = useRouter()
    const form = reactive({
      phone: '',
      code: ''
    })
    const cooldown = ref(0)

    const handleSendCode = () => {
      if (!form.phone) {
        message.error('请输入新手机号')
        return
      }
      cooldown.value = 60
      const timer = setInterval(() => {
        cooldown.value--
        if (cooldown.value <= 0) {
          clearInterval(timer)
        }
      }, 1000)
      message.success('验证码已发送')
    }

    const handleSubmit = () => {
      if (!form.phone || !form.code) {
        message.error('请填写完整信息')
        return
      }
      message.success('手机号修改成功')
      router.back()
    }

    return {
      form,
      cooldown,
      handleSendCode,
      handleSubmit
    }
  }
}
</script>

<style scoped>
.page-container {
  padding: 40px 24px;
  min-height: 100vh;
  background: #f0f2f5;
}

.header-card {
  max-width: 1400px;
  margin: 0 auto 20px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
}

:deep(.header-card .ant-card-body) {
  padding: 12px 24px;
}

.page-title {
  margin: 0;
  font-size: 18px;
  color: rgba(0, 0, 0, 0.85);
}

.form-container {
  max-width: 800px;
  margin: 0 auto;
}

.verify-code {
  display: flex;
  gap: 8px;
}

.send-code-btn {
  min-width: 100px;
}
</style> 